<?php
namespace app\home\model;
use myResponse\Res;
use think\Model;
use think\Db;

class PatrolDeviceM extends Model{
    protected $table = 'patrol_device'; // 设置当前模型对应的完整数据表名称
    protected $pk = 'PatrolDeviceID';

    // 模型初始化
    protected static function init()
    {
        //TODO:初始化内容
    }


    public function listP(){

        $id=input('LineID');
        if(!$id)
            Res::errs('请选择巡检路线！');
        $map['d.LineID']= $id;
        $list = Db::view('patrol_device d', '*')
            ->view('sb s', 'sbdh, sbmc, ggxh, checkStandardId', 'd.sbid=s.sbid', 'left')
            ->view('check_standard c', 'StandardName', 's.checkStandardId=c.StandardId', 'left')
            ->view('sys_user u', 'UserName as CreateName', 'd.Creator=u.UserId', 'left')
            ->order('d.SbSort asc, d.CreateTime desc')
            ->where($map)
            ->select();
        return $list?$list:[];
    }

    public function addOne(){
        $data = input('post.');
        $data['Creator'] = session('user.UserId');
        $data['Updater'] = session('user.UserId');
        $data['UpdateTime'] = date('Y-m-d H:i:s', time());
        $m = new PatrolDeviceM($data);
        // 过滤post数组中的非数据表字段数据
        return $m->allowField(true)->save();
    }

    public function editOne(){
        $data = input('post.');
        $data['Updater'] = session('user.UserId');
        $data['UpdateTime'] = date('Y-m-d H:i:s', time());
        $m = new PatrolDeviceM();
        // 过滤post数组中的非数据表字段数据
        return $m->allowField(true)->update($data);
//  条件修改      return $sup->allowField(true)->save(input('post.'),['c_id' => input('post.id')]);
    }
    public function delOne(){
        return PatrolDeviceM::destroy(input($this->pk));
// 支持批量删除多个数据 User::destroy('1,2,3');
// 或者 User::destroy([1,2,3]);
    }


}